﻿<!DOCTYPE html>
<html>
<head>
    <title>CGI</title>
</head>
<body>
    <h1>Our Page</h1>
    <script>
        //01
        //check for regular expression
        
        var blogText = "Sam I Am";
        var pattern = new RegExp('am', 'g');
        console.log(pattern instanceof RegExp);

        var blogText = "Sam I Am";
        var pattern = /am/g;
        console.log(pattern instanceof RegExp);
        

        //02
        /*
        var blogText = "Sam I Am";
        var pattern = /am/g;
        console.log(pattern.test(blogText));

        var pattern = /bam/g;
        console.log(pattern.test(blogText));
        */

        //03
        // /g  global, search in entire string
        /*
        var blogText = "Sam I Am";
        var pattern = /m/g;
        console.log(pattern.test(blogText));
        console.log(pattern.test(blogText));
        console.log(pattern.test(blogText));
        */

        //04 exec
        /*
        var blogText = "Sam I Am";
        var pattern = /m/g;
        var result = pattern.exec(blogText);
        console.log(result);
        console.log(result[0]);
        console.log(result.index);
        console.log(result.input);

        var blogText = "Sam I Am";
        var pattern = /m/g;
        var result = pattern.exec(blogText);
        console.log(result.index);
        result = pattern.exec(blogText);
        console.log(result.index);

        var blogText = "Sam I Am";
        var pattern = /m/g;
        var result = pattern.exec(blogText);
        while (result) {
            console.log(result.index);
            result = pattern.exec(blogText);
        }
        */

        //05 match
        /*
        var blogText = "Sam I Am";
        var pattern = /m/g;
        var result = blogText.match(pattern);
        console.log(result);

        //lowecase am and uppercase
        //var pattern = /am/g;
        //var pattern = /am/gi; //g=global, i=case in-sensitive
        //var pattern = /[aA]m/g;
        var pattern = /.m/g;
        var result = blogText.match(pattern);
        console.log(result);
        */
    </script>
</body>
</html>